package com.itheima.a04test;

import com.itheima.a01mymap.Student;

import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;

public class Test1 {
    public static void main(String[] args) {
        //班级里有n个学生，实现随机点名器

        //思路：创建对象添加到学生集合里面，然后通过随机索引找到学生并打印学生名字，模拟随机点名

        //创建集合
        ArrayList<Student> list=new ArrayList<>();

        //创建学生对象
        Student s1=new Student("zhangsna",19);
        Student s2=new Student("lisi",21);
        Student s3=new Student("wangewu",23);
        Student s4=new Student("zhaoliu",24);
        Student s5=new Student("wanger",20);
        Student s6=new Student("mazi",66);

        //添加进集合,可以用工具类批量添加
        Collections.addAll(list,s1,s2,s3,s4,s5,s6);

        //随机索引
        Random r=new Random();

        //打印学生姓名
        System.out.println(list.get(r.nextInt(6)).getName());


    }
}
